﻿
#region
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.OleDb;
using System.Data;
using DTO;
#endregion

namespace DAO
{
    public class PhongDAO:Dataprovider
    {
        #region Phuong thuc
        public PhongDAO()
        {
        }

        // lay danh sach phong.
        public ArrayList getDsPhong()
        {
            connect();
            string query = "SELECT * FROM PHONG";
            adapter = new OleDbDataAdapter(query, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            ArrayList arr = ConvertDataSetToArrayList(dataset);

            return arr;
        }

        // lay du lieu dua vao dataRow
        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            PhongDTO p = new PhongDTO();

            p.MaPhong = dt.Rows[i]["MaPhong"].ToString();
            p.LoaiPhong = dt.Rows[i]["LoaiPhong"].ToString();
            p.PhieuGia = (float)dt.Rows[i]["PhieuGia"];
            p.TinhTrang = dt.Rows[i]["TinhTrang"].ToString();
            
            return (object)p;
        }

        public void insert(PhongDTO info)
        {
            string insertCommand = "INSERT INTO PHONG VALUES('" +
                info.MaPhong + "', '" +
                info.LoaiPhong + "', '" +
                info.PhieuGia + "', '" +
                info.TinhTrang + ")";

            executeNonQuery(insertCommand);
        }

        public void update(PhongDTO info)
        {
            string updateCommand = "UPDATE PHONG " +
                                    "SET LoaiPhong = '" + info.LoaiPhong + "', " +
                                    " PhieuGia = '" + info.PhieuGia + "', " +
                                    " TinhTrang = '" + info.TinhTrang + "', " +
                                    " WHERE MaPhong = '" + info.MaPhong + "'";


            executeNonQuery(updateCommand);
        }

        public void delete(string maP)
        {
            string deleteCommand = "DELETE FROM PHONG WHERE MaPHONG = '" + maP + "'";
            executeNonQuery(deleteCommand);
        }
        #endregion
    }
}
